package pathfinding;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Collection;

import javax.swing.JFrame;
import javax.swing.JPanel;

public class DebugPF extends JPanel {
	private int size=15;
	private boolean[][] map;
	private Collection<Node> nodes;
	
	public DebugPF() {
		JFrame f = new JFrame("debug");
		this.setBackground(Color.YELLOW);
		this.setPreferredSize(new Dimension(1000, 1000));
		this.setOpaque(true);
		f.add(this);
		f.pack();
		f.setVisible(true);
	}
	
	
	public void show(boolean[][] map, Collection<Node> nodes) {
		this.map = map;
		this.nodes = new ArrayList<Node>();
		this.nodes.addAll(nodes);
		repaint();
	}
	
	@Override
	public void paintComponent(Graphics g) {
		if (map == null) return;
		
		g.clearRect(0, 0, 1000, 1000);
		
		for (int i=0; i<map.length; ++i){
			for (int j=0; j<map[i].length; ++j) {
				Color c = map[i][j]? Color.WHITE: Color.BLACK;
				g.setColor(c);
				g.fillRect(i*size, j*size, size, size);
			}
		}
		
		g.setColor(Color.CYAN);
		for (Node n: nodes) {
			g.fillRect(n.x*size, n.y*size, size, size);
		}
		g.setColor(Color.GREEN);
		for (Node n: nodes) {
			for (Node m: n.neigh.keySet()) {
				g.drawLine(n.x*size+size/2, n.y*size+size/2, m.x*size+size/2, m.y*size+size/2);
			}
		}
	}
}
